package com.lineage.server.command.executor;

import com.lineage.data.item_armor.set.ArmorSet;
import com.lineage.server.datatables.ItemTable;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.templates.L1Item;
import java.util.HashMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class L1CreateItemSet implements L1CommandExecutor {
  private static final Log _log = LogFactory.getLog(L1CreateItemSet.class);
  
  public static L1CommandExecutor getInstance() {
    return new L1CreateItemSet();
  }
  
  public void execute(L1PcInstance pc, String cmdName, String arg) {
    try {
      int key = Integer.parseInt(arg);
      HashMap<Integer, ArmorSet> map = ArmorSet.getAllSet();
      ArmorSet armorSet = map.get(Integer.valueOf(key));
      int get_ids[], length = (get_ids = armorSet.get_ids()).length;
      int i = 0;
      while (i < length) {
        int itemid = get_ids[i];
        L1Item temp = ItemTable.get().getTemplate(itemid);
        if (temp != null) {
          pc.getInventory().storeItem(itemid, 1L);
          pc.sendPackets((ServerBasePacket)new S_ServerMessage(403, String.valueOf(String.valueOf(temp.getNameId())) + "(ID:" + itemid + ")"));
        } else {
          _log.error("找不到指定编号物品:" + itemid + " 套装编号:" + arg + " 执行的GM:" + pc.getName());
        } 
        i++;
      } 
    } catch (Exception e) {
      _log.error("错误的GM指令格式: " + getClass().getSimpleName() + " 执行的GM:" + pc.getName());
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(261));
    } 
  }
}
